package com.apexsoft.aas.service.grpc;

import com.alibaba.fastjson.parser.ParserConfig;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.util.TypeUtils;

public class FastjsonGrpcSupport {
    private static final ParserConfig config = new ParserConfig();
    private static final SerializeConfig serializeConfig = new SerializeConfig();

    static {

        TypeUtils.addMapping(BooleanValue.instance.type(), BooleanValue.class);
        config.putDeserializer(BooleanValue.class, BooleanValue.instance);
        serializeConfig.put(Boolean.class, BooleanValue.instance);
        serializeConfig.put(boolean.class, BooleanValue.instance);

        TypeUtils.addMapping(DoubleValue.instance.type(), DoubleValue.class);
        config.putDeserializer(DoubleValue.class, DoubleValue.instance);

        serializeConfig.put(Double.class, DoubleValue.instance);
        serializeConfig.put(double.class, DoubleValue.instance);

        TypeUtils.addMapping(FloatValue.instance.type(), FloatValue.class);
        config.putDeserializer(FloatValue.class, FloatValue.instance);

        serializeConfig.put(Float.class, FloatValue.instance);
        serializeConfig.put(float.class, FloatValue.instance);

        TypeUtils.addMapping(Int32Value.instance.type(), Int32Value.class);
        config.putDeserializer(Int32Value.class, Int32Value.instance);

        serializeConfig.put(Integer.class, Int32Value.instance);
        serializeConfig.put(int.class, Int32Value.instance);

        TypeUtils.addMapping(Int64Value.instance.type(), Int64Value.class);
        config.putDeserializer(Int64Value.class, Int64Value.instance);

        serializeConfig.put(Long.class, Int64Value.instance);
        serializeConfig.put(long.class, Int64Value.instance);

        TypeUtils.addMapping(StringValue.instance.type(), StringValue.class);
        config.putDeserializer(StringValue.class, StringValue.instance);

        serializeConfig.put(String.class, StringValue.instance);

        TypeUtils.addMapping(UInt32Value.instance.type(), UInt32Value.class);
        config.putDeserializer(UInt32Value.class, UInt32Value.instance);

        TypeUtils.addMapping(UInt64Value.instance.type(), UInt64Value.class);
        config.putDeserializer(UInt64Value.class, UInt64Value.instance);

    }

    public static ParserConfig getParserConfig() {


        return config;
    }

    public static SerializeConfig getSerializeConfig() {

        return serializeConfig;
    }

}
